<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>按钮</button>
    <script>
        let obj = {
            myname: "zhangsan",
            age: 20
        }
        var btn = document.querySelector('button');
        btn.onclick = function () {
            window.location.href = 'b.html';
        }
        // 把对象转成固定格式的字符串name=zhangsan&age=20
        function o2s(obj) {
            let keys = Object.keys(obj);
            let values = Object.values(obj);
            var arr = keys.map(function(item, index) {
                return `${item}=${values[index]}`;
            })
            console.log(arr);
            return arr.join('&');
            // console.log(keys, values);
        }
        o2s(obj);
    </script>
</body>
</html>